//
//  QZStreetViewController.m
//  WeiWeiHaircut
//
//  Created by apple on 15/12/27.
//  Copyright © 2015年 超群. All rights reserved.
//

#import "QZStreetViewController.h"
#import "QZAddressInfo.h"
@interface QZStreetViewController ()

@end

@implementation QZStreetViewController
{
    NSString *_cityId;
    NSString *_cityName;
    NSDictionary *_dataDic;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self titleWithSting:@"街道"];
    
    [self addBtnOnNavWithTitle:@"返回" andImageName:@"返回" andTarget:self andAction:@selector(backAction) andFrame:CGRectMake(0, 0, 45, 20) andDirection:left];
    
    [self createTableViewWithPlainStyle:NO andSeparatorStyleNone:NO andBackGroudImageName:nil];
    [self registCellWithClassName:[UITableViewCell class] addIdentifier:@"cell" addHeight:44];
    
    [self requestData];
    
}
-(void)requestData
{

    [self requestWithKeys:@[@"city_id"] andValues:@[@([_provinceId integerValue])] andUrlKey:@"City.GetListInfo" isCache:YES];
}
-(void)request_POST_FinishValue:(id)value tagNSString:(NSString *)tag
{

    
    if ([tag isEqualToString:@"City.GetListInfo"]) {
        if ([value[@"data"][@"status"] intValue] == 100) {
            NSArray *dataArray = value[@"data"][@"data"][@"list"];
       
            [self.tableSource addObject:dataArray];
            [self.tableView reloadData];
        }

    }
    if ([tag isEqualToString:@"修改用户地址"]) {
        if ([value[@"data"][@"status"] integerValue] != 100) {
            [[iToast makeText:@"更新失败"] show];
        }else{
            NSDictionary *dic = [NSDictionary dictionaryWithDictionary:[[QZAddressInfo shared] showAddressInfo]];
            [QZAddressInfo clearData];
            NSString *address = [NSString stringWithFormat:@"%@%@%@%@",dic[@"sheng"],dic[@"shi"],dic[@"qu"],dic[@"jie"]];
            [[TMCache sharedCache] setObject:address forKey:@"address"];
            for (UIViewController *vc in self.navigationController.childViewControllers) {
                if ([NSStringFromClass([vc class]) isEqualToString:@"ModifyInfoViewController"]) {
                    [self.navigationController popToViewController:vc animated:YES];
                    return;
                }
            }
        }
        
    }
    
}
-(void)loadCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
//    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = self.tableSource[indexPath.section][indexPath.row][@"name"];
}
-(void)actionAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *name = self.tableSource[indexPath.section][indexPath.row][@"name"];
    NSString *jieID = self.tableSource[indexPath.section][indexPath.row][@"id"];
    [[QZAddressInfo shared] addressSetobjct:name forkey:@"jie"];
    [[QZAddressInfo shared] addressSetobjct:jieID forkey:@"jieID"];
    

    if (_isAddaddress) {
        NSLog(@"收货地址修改增加");
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:[[QZAddressInfo shared] showAddressInfo]];
        NSString *address = [NSString stringWithFormat:@"%@%@%@%@",dic[@"sheng"],dic[@"shi"],dic[@"qu"],dic[@"jie"]];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"添加地址" object:address];
        
        for (UIViewController *vc in self.navigationController.childViewControllers) {
            if ([NSStringFromClass([vc class]) isEqualToString:@"QZAddressViewController"]) {
                [self.navigationController popToViewController:vc animated:YES];
                return;
            }
        }
        
    }else{
        NSLog(@"修改地址");
        NSDictionary *addressInfo = [[QZAddressInfo shared] showAddressInfo];
        
        NSString *url = [NSString stringWithFormat:@"%@%@",newPublicURL,@"User.GetSetCity"];
        NSDictionary *dictionary = @{
                                     @"user_id":[QZUserInfo userId],
                                     @"province_id":addressInfo[@"shengID"],
                                     @"city_id":addressInfo[@"shiID"],
                                     @"district_id":addressInfo[@"quID"],
                                     @"street_id":addressInfo[@"jieID"]
                                     };
        [self.request QZRequest_POST:url parameters:dictionary tagNSString:@"修改用户地址" stopRequest:YES isSerializer:NO isCache:NO];
    }
 
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"全部";
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}
-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
